#ifndef PROGRAMEDITOR_H
#define PROGRAMEDITOR_H

#include <QWidget>
#include <baseeditor.h>
#include <grouptreeitemview.h>
#include <material_editor/basematerialeditor.h>
#include <materialdatalistmodel.h>
#include <materialmanager.h>
#include <ui_programeditor.h>


class MaterialView;
class ProgramBindingItemDelegate;
class ProgramBindingModel;
class ProgramErrorModel;
class ProgramShaderProgramListModel;
class ProgramEditor : public BaseMaterialEditorWidget
{
  Q_OBJECT
private:
  Ui::ProgramEditor _gui;
  Program*           _program;
  GroupTreeItemView   *_groupView;
  MaterialView        *_materialView;

  MaterialDataListModel*          _shaderModel;
  AllProgramShaderDelegator*      _shaderDelegator;
  ProgramBindingModel*            _bindingModel;
  ProgramShaderProgramListModel*  _programModel;
	ProgramErrorModel*							_errorModel;
  ProgramBindingItemDelegate*     _bindingDelegate;

  Program::ShaderProgram* GetCurrentProgram ();

  void ParseAndAddInfoLog (const QString& programName, Shader* shader, const QString& infoLog);

private slots:

  void UpdateGUI();
  void ContentChanged();
  void EnableDisableButtons ();

  void ProgramChanged ();
  void ShaderChanged ();

  void ProgramSelectionChanged (QModelIndex index, QModelIndex);
  void ShaderSelectionChanged (QModelIndex index, QModelIndex);

  void on_pushButtonAddProgram_clicked ();
  void on_pushButtonRemoveProgram_clicked ();
  void on_pushButtonAddShader_clicked ();
  void on_pushButtonRemoveShader_clicked ();
  void on_pushButtonUpdate_clicked ();
  void on_pushButtonAutoAssign_clicked ();
  void on_listViewShaders_doubleClicked (const QModelIndex &index);
  void on_treeViewError_doubleClicked (const QModelIndex& index);
public:
  ProgramEditor(Program* shader, MaterialView* view, QWidget *parent = 0);

  void SetProgram(Program* program);
  Program* GetProgram();

public slots:
  virtual void Save ();
  virtual void Compile ();

};

#endif // SHADEREDITOR_H
